package com.face.operate.jsu;

import java.io.File;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.util.NewBeanInstanceStrategy;

import com.face.bean.jsu.FindPopulation;
import com.face.sql.jsu.FindDao;
import com.face.sql.jsu.JDBCUtil;
import com.face.sql.jsu.LostDao;

public class FindToken_Operate {

	public FindDao dao   = new  FindDao();
	 
	public void Save(String id,String path,String province,String city,String location,Timestamp date,String message){
	
			dao.insertData(id, path,province,city,location,date,message);
		
	}
	/*
	 * 通过指定的faceid查询对应的元组
	 */
	public FindPopulation selectByfaceId(String id){
		return dao.selectByfaceid(id);
	}
	/*
	 * 通过指定的facepath查询faceid
	 */
	public String selectByfacePath(String path){
		return dao.selectByfacepath(path);
	}
	/*
	 * 通过指定的id删除一行纪录
	 */
	public void deleteById(String id){
		dao.deleteByid(id);
	}
	/*
	 * 通过指定的路径删除一行纪录
	 */
	public void deleteByPath(String path){
		dao.deleteBypath(path);
	}
	/*
	 * 用于更新faceid通过id,path映射
	 */
	public void updateById(String id,String path){
		dao.updateByid(id, path);
	}
	/*
	 * 用于更新facepath通过id,path的映射
	 */
	public void updateByPath(String id,String path){
		dao.updateBypath(id, path);
	}
	/*
	 * 用于查询所有数据
	 */
	public Map<String, String> selectAll(){
		Map<String,String> map =new HashMap<String, String>();
		map  = dao.selectAll();
		return map;
	}
	/*
	 * 用于显示Map的数据
	 */
	public void showMap(Map<String,String> map){
		for(Map.Entry<String, String> entry: map.entrySet()){
			System.out.println("Key = "+ entry.getKey()+" Value = "+entry.getValue());
		}
	}
	
	/*
	 * 用于返回指定字符串的token
	 */
	public String get_token(String tag){
		String get_token = "";
		get_token = tag.substring(tag.indexOf("face_token")+14,tag.indexOf("face_token")+46);
		return get_token;
	}
	/*
	 * 用于返回指定路径的所有为jpg或者png的图片的路径集合
	 */
	public List<String> Faceadd(String strPath){
		List<String> filelist = new ArrayList<String>();
		File dir = new File(strPath);
		File[] files = dir.listFiles();
		if(files != null){
			for(int i = 0 ;i < files.length; i++){
				String filename = files[i].getName();
			    if(filename.endsWith("jpg")||filename.endsWith("png")){
					System.out.println("文件路径："+files[i].getAbsolutePath()+"文件名字"+filename);
					filelist.add(files[i].getAbsolutePath());
				}
			}
		}
		return filelist;
	}
	public double returnConfidence(String src){
		return Double.parseDouble(src.substring(src.indexOf("confidence")+13, src.indexOf("confidence")+17));
	}
}
